package concurrent;

import java.util.concurrent.atomic.AtomicInteger;

public class ThreadLocalTest {

	private static AtomicInteger count = new AtomicInteger(10);
	private static final ThreadLocal<AtomicInteger> local = new ThreadLocal<AtomicInteger>(){

		@Override
		protected AtomicInteger initialValue() {
			return count;
		}
	}; 
	
	public static void main(String[] args) {
		
		Inner in1 = new Inner();
		Inner in2 = new Inner();
		Inner in3 = new Inner();
		
		in1.start();
		in2.start();
		in3.start();
	}
	
	static class Inner extends Thread{

		@Override
		public void run() {

			AtomicInteger initValue = local.get();
			initValue.incrementAndGet();
			System.out.println(currentThread().getName() + ":" + local.get().get());
		}
	}
}
